package org.kaindorf.kainflix.metadata.controller;

import org.kaindorf.kainflix.metadata.repository.entity.Product;
import org.kaindorf.kainflix.metadata.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Iterator;


@RestController
public class ProductController {

    @Autowired
    private ProductService productService;

    @RequestMapping("/products")
    public Iterable<Product> allProducts() {
        return productService.getAllProducts();
    }

    @RequestMapping(value = "/products", method = RequestMethod.PUT)
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void addProduct(@RequestBody Product product) {
        productService.saveProduct(product);
    }

}
